package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Comment;
import com.tanhua.model.mongo.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * Description:
 * Author:asur
 * Date:2022-04-21
 * Time:15:15
 */
@DubboService
public class FocusApiImpl implements FocusApi{

    @Autowired
    private MongoTemplate mongoTemplate;

    //判断是否存在
    @Override
    public Boolean isFocus(String videoUserId, Long userId) {
        Criteria criteria = Criteria.where("userId").is(userId)
                .and("VideoUserId").is(Long.valueOf(videoUserId));
        Query query = Query.query(criteria);
        return mongoTemplate.exists(query, FocusUser.class);

    }
    //保存
    @Override
    public void save(FocusUser focusUser) {
         mongoTemplate.save(focusUser);
    }
    //删除
    @Override
    public void delete(FocusUser focusUser) {
        Criteria criteria = Criteria.where("userId").is(focusUser.getUserId())
                .and("VideoUserId").is(focusUser.getVideoUserId());
        Query query = Query.query(criteria);
        mongoTemplate.remove(query, FocusUser.class);
    }
}
